<!--_meta 作为公共模版分离出去-->
<#include "include/_meta.html">
<!--/meta 作为公共模版分离出去-->

<title>添加管理员 - 管理员管理</title>
<meta name="keywords" content="汽车租赁">

</head>
<body>
<article class="page-container">
    <form class="form form-horizontal" id="form-admin-add">
        <div width="900px">
            <div style="float:left;width:500px;height:300px;">
                <div class="row cl">
                    <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色名称：</label>
                    <div class="formControls col-xs-8 col-sm-9">
                        <input type="text" class="input-text" value="" placeholder="角色名称"
                               style="width:300px;" id="rolename" name="rolename">
                    </div>
                </div>
                <div class="row cl">
                    <label class="form-label col-xs-4 col-sm-3">是否启用：</label>
                    <div class="formControls col-xs-8 col-sm-9 skin-minimal">
                        <div class="radio-box">
                            <input name="isabled" type="radio" id="us_1" value="1" checked>
                            <label for="sex-1">启用</label>
                        </div>
                        <div class="radio-box">
                            <input type="radio" id="us_0" name="isabled" value="0">
                            <label for="sex-2">禁用</label>
                        </div>
                    </div>
                </div>
                <div class="row cl">
                    <label class="form-label col-xs-4 col-sm-3">角色描述：</label>
                    <div class="formControls col-xs-8 col-sm-9">
                        <textarea id="decrib" style="width:300px;" name="decrib" cols="" rows="" class="textarea"
                                  placeholder="说点什么...100个字符以内" dragonfly="true"
                                  onKeyUp="textarealength(this,100)"></textarea>
                        <p class="textarea-numberbar" style="width:300px;"><em class="textarea-length">0</em>/100</p>
                    </div>
                </div>
            </div>
            <div style="float:right;width:300px">
                <div vlass="row cl">
                    <label class="form-label col-xs-4 col-sm-6"><span class="c-red">*</span>选择权限资源：</label>
                    <div class="formControls col-xs-8 col-sm-9" style="width:300px;">
                        <div id="rMenu" style="width:100%;height:100%;float:left;">
                            <ul style="height:700px;" id="treeDemo" class="ztree">
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row cl">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                    <input class="btn btn-primary radius" type="button" value="&nbsp;&nbsp;提交&nbsp;&nbsp;"
                           onclick="$('#form-admin-add').submit()"/>
                    <input class="btn btn-primary radius" type="button" onclick="hiddenMemu()" value="取消"/>
                </div>
            </div>
        </div>

    </form>
</article>

<!--_footer 作为公共模版分离出去-->
<#include "include/_footer.html">
<!--/_footer /作为公共模版分离出去-->
<script type="text/javascript" src="/lib/webuploader/0.1.5/webuploader.min.js"></script>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">

    var zNodes;
    var setting = {
        view: {
            dblClickExpand: false,
            showLine: false,
            selectedMulti: false
        },
        data: {
            simpleData: {
                enable: true,
                idKey: "id",
                pIdKey: "pId",
                rootPId: ""
            }
        },
        check: {
            enable: true,
            chkStyle: "checkbox",
            chkboxType: {"Y": "ps", "N": "ps"}
        }
    };

    function resourceList() {
        zTree = $.fn.zTree.getZTreeObj("treeDemo");
        checkCount = zTree.getCheckedNodes(true);
        console.log(checkCount);
        let array = new Array();
        for (var i = 0; i < checkCount.length; i++) {
            array[i] = checkCount[i].id;
        }
        return array;
    }
    function hiddenMemu(){
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }
    var zTree;
    $(function () {
        $.ajax({
            type: "get",
            url: "/resources/getResources",
            dataType: "json",
            async: false,
            success: function (data) {
                console.log (data);
                zNodes = data;
            }
        });

        $.fn.zTree.init($("#treeDemo"), setting, zNodes);
        zTree = $.fn.zTree.getZTreeObj("treeDemo");


        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });


        $("#form-admin-add").validate({
            onkeyup: false,
            focusCleanup: true,
            success: "valid",
            rules: {
                rolename: {
                    required: true,
                },
                decrib: {
                    required: true
                }
            },
            messages: {
                rolename:{
                    required: " "
                },
                decrib: {
                    required: " "
                }
            },
            submitHandler: function (form) {
                let array = resourceList();
                $.ajax({
                    type: 'post',
                    contentType: "application/json;charset=utf-8",
                    url: '/roles/addRole?checkAll='+array,
                    data:JSON.stringify({
                            'rolename': $("#rolename").val(),
                            'isabled': $('input[name="isabled"]:checked').val(),
                            'decrib': $("#decrib").val(),
                    }),
                    success: function (data) {
                        console.log('提交成功！');
                        hiddenMemu();
                    }

                });
            }
        });

    });

</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>